<template>
	<view class="content">
		<view class="cons">
			<uni-swipe-action class="bradio" :options="options1" @click="bindClick(item.id)" v-for="(item, index) in list" :key="index">
				<view class="list flexs1">
					<view class="list_left" @click="goselect(item.id)">
						<view class="name">
							<text>{{item.name}}</text>
							<text class="small text-gray">{{item.mobile}}</text>
						</view>
						<view class="address small">{{item.address}}</view>
					</view>
					<image class="list_right" src="../../static/img/bianji.png" @click="editorAddress(item.id)"></image>
				</view>
			</uni-swipe-action>
		</view>
		<view class="btns text-white text-bold text-center" @click="addAddress">添加新地址</view>
	</view>
</template>

<script>
	import uniSwipeAction from '@/components/uni-swipe-action/uni-swipe-action.vue'
	export default {
		components: {
			uniSwipeAction
			// uniList,
			// uniListItem
		},
		data() {
			return {
				isOpened: false,
				list:[],
				options1: [{
					text: '删除',
					style: {
						backgroundColor: '#FF4242'
					}
				}],
				is_select:0
			}
		},
		onLoad(option) {
			if(option.is_select){
				this.is_select = option.is_select;
			}
		},
		onShow(){
			this.initdata();
		},
		methods: {
			//选择
			goselect(id){
				if(this.is_select==1){
					var pages = getCurrentPages();
					var currPage = pages[pages.length - 1]; //当前页面
					var prevPage = pages[pages.length - 2]; //上一个页面  
					// prevPage.setData({
					// 		address_id:id
					// })
					prevPage.$vm.address_id = id; 
					uni.navigateBack({
						delta:1
					})
					// uni.navigateTo({
					// 	url:'../downorder/downorder?address_id='+id
					// })
				}
			},
			//初始化数据
			initdata(){
				this.$common.requests('/api/shop/myaddress').then(res =>{
					if(res.data.code == 1){
						this.list = res.data.data;
					}else{
						this.$api.msg(res.data.msg)
					}
				})
			},
			bindClick(id) {
				var obj = {
					address_id: id
				}
				this.$common.requests('/api/shop/deladdress', obj).then(res => {
					if (res.data.code == 1) {
						this.initdata();
					} 
					this.$api.msg(res.data.msg)
				})
			},
			//新增地址
			addAddress(){
				uni.navigateTo({
					url:'../addAddress/addAddress?is_select='+this.is_select
				})
			},
			//编辑地址
			editorAddress(id){
				uni.navigateTo({
					url:'../addAddress/addAddress?address_id='+id+'&is_select='+this.is_select
				})
			}
		}
	}
</script>

<style>
	.content{
		background: #F9F9F9;
		width: 100vw;
		height: 100vh;
	}
	.cons{
		padding: 30upx;
		height: 80%;
		overflow-y: scroll;
	}
	.bradio{
		border-radius: 20upx;
		margin-bottom: 30upx;
	}
	.list{
		padding: 30upx;
		background: #FFFFFF;
	}
	.list_left{
		width: 90%;
	}
	.small{
		font-size: 28upx;
	}
	.address{
		overflow: hidden;
		text-overflow:ellipsis;
		white-space: nowrap;
		margin-top: 10upx;
	}
	.list_right{
		width: 35upx;
		height: 35upx;
	}
	.btns{
		width: 76%;
		padding: 25upx 0;
		background: #14C7CE;
		position: fixed;
		border-radius: 15upx;
		bottom: 60upx;
		left: 12%;
		font-size: 30upx;
	}
</style>
